﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PushBox.Core
{
    public class Box : Position
    {
        public void Move(MoveType moveType)
        {
            switch (moveType)
            {
                case MoveType.Up:
                    Y--;
                    break;
                case MoveType.Down:
                    Y++;
                    break;
                case MoveType.Left:
                    X--;
                    break;
                case MoveType.Right:
                    X++;
                    break;
            }
        }

        /// <summary>
        /// 尝试移动
        /// </summary>
        /// <param name="moveType"></param>
        public bool TryMove(MoveType moveType)
        {
            Position p = null;

            switch (moveType)
            {
                case MoveType.Up:
                    p = this.Map.GetObject(this.X, this.Y - 1);
                    break;
                case MoveType.Down:
                    p = this.Map.GetObject(this.X, this.Y + 1);
                    break;
                case MoveType.Left:
                    p = this.Map.GetObject(this.X - 1, this.Y);
                    break;
                case MoveType.Right:
                    p = this.Map.GetObject(this.X + 1, this.Y);
                    break;
            }
            if (p is Wall || p is Box) return false;
            this.Move(moveType);
            return true;
        }
    }
}
